package org.lex.ftplist.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.lex.ftplist.core.Index;
import org.lex.ftplist.ui.common.CachedIndeiesPane;
import org.lex.ftplist.ui.common.FLDialog;

public class ChooseCachedFtpDialog extends FLDialog {
	public static Index showDialog() {
		ChooseCachedFtpDialog d = new ChooseCachedFtpDialog();
		d.setVisible(true);
		System.out.println("Selected Index=" + d.getSelectedIndex());
		return d.getSelectedIndex();
	}

	private CachedIndeiesPane pane = null;
	private Index selection = null;

	public Index getSelectedIndex() {
		return selection;
	}

	public ChooseCachedFtpDialog() {
		this.setSize(200, 200);
		this.moveToParentCenter();
		this.setModal(true);
		this.setTitle("Cache");

		this.initComponents();
	}

	private void initComponents() {
		pane = new CachedIndeiesPane();
		this.setContentPane(pane);

		pane.getCancelButton().addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				selection = null;
				dispose();
			}
		});
		pane.getOkButton().addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				selection = pane.getSelectedIndex();
				dispose();
			}
		});
	}
}
